package com.bupt.controller.common;

import com.bupt.annotation.AccessLimit;
import com.bupt.constants.ResponseResult;
import com.bupt.dto.sys.LoginUserDto;
import com.bupt.service.common.KangHuiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

@Slf4j
@RestController
@Api(tags = {"项目的抗毁部分"})
@RequestMapping("/api")
public class KangHuiController {

    @Resource
    private KangHuiService kangHuiService;

    @ApiOperation("根据WeaverId获得链路节点，组合断后业务集合")
    @AccessLimit(interfaceName = "链路节点组合断", isEnableClickLimit = false)
    @PostMapping(value = "/kanghui/{pId}/getBreakTogether")
    public Object getBreakOnce(@ApiIgnore LoginUserDto loginUserDto,
                               @PathVariable("pId") String pId,
                               @RequestParam("fiberLinkIds") String[] fiberLinkIds,
                               @RequestParam("nodeIds") String[] nodeIds) {
        try {
            Object o = kangHuiService.getBreak(loginUserDto,pId, Arrays.asList(fiberLinkIds),Arrays.asList(nodeIds));
            return ResponseResult.createOK(o);
        } catch (Exception e) {
            return ResponseResult.createFail(e.getMessage());
        }
    }

    @ApiOperation("根据WeaverId获得链路节点，依次单断后业务集合")
    @AccessLimit(interfaceName = "链路节点依次单断", isEnableClickLimit = false)
    @PostMapping(value = "/kanghui/{pId}/getBreakOneByOne")
    public Object getBreakOneByOne(@ApiIgnore LoginUserDto loginUserDto,
                                   @PathVariable("pId") String pId,
                                   @RequestParam("fiberLinkIds") String[] fiberLinkIds,
                                   @RequestParam("nodeIds") String[] nodeIds) {
        try {
            Object o = kangHuiService.getBreakOneByOne(loginUserDto,pId, Arrays.asList(fiberLinkIds),Arrays.asList(nodeIds));
            return ResponseResult.createOK(o);
        } catch (Exception e) {
            return ResponseResult.createFail(e.getMessage());
        }
    }
    @ApiOperation("获取单断端口集合，依次单断后业务")
    @AccessLimit(interfaceName = "端口依次单断", isEnableClickLimit = false)
    @PostMapping(value = "/kanghui/{pId}/getBreakPort")
    public Object getBreakPort(@ApiIgnore LoginUserDto loginUserDto,
                                   @PathVariable("pId") String pId,
                                   @RequestParam("nodeId") String nodeId,
                                   @RequestParam("portIds") Integer[] portIds) {
        try {
            Object o = kangHuiService.getBreakPort(loginUserDto,pId,nodeId, Arrays.asList(portIds));
            return ResponseResult.createOK(o);
        } catch (Exception e) {
            return ResponseResult.createFail(e.getMessage());
        }
    }

    @ApiOperation("导出组合断的抗毁数据")
    @AccessLimit(interfaceName = "导出组合断的抗毁数据")
    @GetMapping(value = "/kanghui/{pId}/getBreakTogether")
    public Object zuheExport(
            @ApiIgnore LoginUserDto loginUserDto,
            @PathVariable("pId") String pId,
            HttpServletResponse response
    ){
        try{
            HttpServletResponse r = kangHuiService.zuheExport(response,loginUserDto,pId);
            return null;
        }
        catch(Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    @ApiOperation("导出多次单断的抗毁数据")
    @AccessLimit(interfaceName = "导出多次单断的抗毁数据")
    @GetMapping(value = "/kanghui/{pId}/getBreakOneByOne")
    public Object oneByOneExport(
            @ApiIgnore LoginUserDto loginUserDto,
            @PathVariable("pId") String pId,
            HttpServletResponse response
    ){
        try{
            HttpServletResponse r = kangHuiService.oneByOneExport(response,loginUserDto,pId);
            return null;
        }
        catch(Exception e) {
            e.printStackTrace();
            return null;
        }
    }


}
